<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用methods实现姓名案例</title>
  </head>

  <body>
    <div id="app">
      <div>姓:<input type="text" v-model:value="firstName"></div>
      <div>名:<input type="text" v-model:value="lastName"></div>
      <div>姓名:{{getFullName()}}</div>
      <!-- <button @click="getFullName">获取姓名</button> -->
    </div>
  </body>
  <script src="../js/vue.js"></script>
  <script>
    /* 
    首先一上来,Vue会解析这个模板，getfullName方法会被调用一次
    然后后面只要有属性发生变化，getFullName方法都会重新被调用一次
    */
    new Vue({
      el: "#app",
      data: {
        firstName: '张',
        lastName: '三'
      },
      methods: {
        getFullName() {
          console.log("getFullName方法被调用了");
          return this.firstName + this.lastName
        }
      },
    })
  </script>

</html>